<?php

namespace addons\tools\controller\api\v1;

use addons\tools\model\UserVip;
use app\common\controller\Api;

class User extends Api
{

    protected $noNeedRight = ['*'];

    public function index()
    {
        $userInfo = \addons\tools\model\User::field('id,username,nickname,avatar,gender')->with([
            'userVip'        => function ($query) {
                $query->alias('v')->join('user_meal m','v.meal_id=m.id')->field('user_id,meal_id,m.name as meal_name,validity_time');
            }, 'userVipRule' => function ($query) {
                $query->alias('a')->join('tools b','a.tool_id=b.id')
                    ->field('a.user_id,a.id,a.tool_id,a.value as number,b.name');
            }])->where('id', $this->auth->id)->find();
//        $userInfo->vip_rule = UserVip::field('user_id,validity_time')->where('user_id', $userInfo->id)->find();
        $this->success(__('获取数据成功'), $userInfo);
    }
}